import * as MyCom from './components';
import { connect } from 'dva';

const Network = ({ network, dispatch }) => {
    const actionProps = {
      actionList: [
        {
          icon: 'plus',
          title: '创建',
          key: 'create',
          type: 'primary',
          click: () => {
            dispatch({ type: 'docker/network/visibleCreateState', payload: { visible: true } });
          },
        }, {
          icon: 'delete',
          title: '删除',
          key: 'delete',
          type: 'danger',
          click: () => {
            if (network.selectKeys.length > 0) {
              dispatch({ type: 'docker/network/remove', payload: { Id: network.selectKeys } });
            }
          },
        },
      ],
      actionSize: 'large',
    };
    const listProps = {
      dataList: network.networkList,
      dispatch,
      selectKeys: network.selectKeys,
    };
    const createProps = {
      formList: [
        {
          label: 'name',
          key: 'name',
          type: 'input',
          required: true,
          placeholder: 'name',
        },
        {
          label: 'driver',
          key: 'driver',
          type: 'select',
          option: [
            {
              label: 'bridge',
              key: 'bridge',
              value: 'bridge',
            },
          ],
        },
        {
          label: 'subnet',
          key: 'subnet',
          type: 'input',
          required: true,
          placeholder: '172.168.52.0/24',
        },
        {
          label: 'gateway',
          key: 'gateway',
          type: 'input',
          required: true,
          placeholder: '172.168.52.1',
        },
        {
          label: 'scope',
          key: 'scope',
          type: 'select',
          option: [
            {
              label: 'local',
              key: 'local',
              value: 'local',
            }, {
              label: 'global',
              key: 'global',
              value: 'global',
            }, {
              label: 'swarm',
              key: 'swarm',
              value: 'swarm',
            },
          ],
        },
      ],
      submitForm: (data) => {
        dispatch({ type: 'docker/network/create', payload: { data } });
      },
      visible: network.visibleCreate,
      onClose: () => {
        dispatch({ type: 'docker/network/visibleCreateState', payload: { visible: false } });
      },
    };
    return (
      <div>
        <h2>network</h2>
        <MyCom.Action {...actionProps}/>
        <MyCom.List {...listProps}/>
        <MyCom.Create {...createProps}/>
      </div>
    );
  }
;
export default connect((_) => ({ network: _['docker/network'] }))(Network);
